#ifndef _IOT_CAN_H_
#define _IOT_CAN_H_

#define CAN1 1
#define CAN2 2

#define CAN_ID_STD 0
#define CAN_ID_EXT 1

#define CAN_RTR_DATA 0
#define CAN_RTR_RMT 1

#define CAN_MODE_CONFIG   0x80 
#define CAN_MODE_LISTEN   0x60 
#define CAN_MODE_LOOPBACK 0x40 
#define CAN_MODE_SLEEP    0x20 
#define CAN_MODE_NORMAL   0x00

typedef union {
	unsigned char regData[13];
	struct {
		unsigned int EID:18;
		unsigned int :1;
		unsigned int IDE:1;
		unsigned int :1;
		unsigned int SID:11;
		unsigned char DLC:4;
		unsigned char :2;
		unsigned char RTR:1;
		unsigned char :1;
		unsigned char data[8];
	}/*__attribute__((packed)) */CanMsg;
}uCAN_Msg;

/*typedef union {
	U8 regData[5];
	struct {
		U32 EID:18;
		U32 :1;
		U32 IDE:1;
		U32 :1;
		U32 SID:11;
	}Bits;
}uMask,uFilter;*/

typedef enum {
	CAN_BAUD_100Kbps = 0x09,
	CAN_BAUD_125Kbps = 0x07,
	CAN_BAUD_250Kbps = 0x03, 
	CAN_BAUD_500Kbps = 0x01
}CAN_Baudrate;

extern void iot_CAN_RunEnvInit();
extern void iot_CAN_Reset(iot_uint8_t can_index);
extern void iot_CAN_SetWorkMode(iot_uint8_t can_index, iot_uint8_t mode);
extern void iot_CAN_SetBaudrate(iot_uint8_t can_index, CAN_Baudrate baud);
extern void iot_CAN_Send(iot_uint8_t can_index, uCAN_Msg *msg);
extern iot_bool_t iot_CAN_Receive(iot_uint8_t can_index, uCAN_Msg *msg);
extern void iot_CAN_EnableWakeUpInterrupt(iot_uint8_t can_index);
extern void iot_CAN_WakeUpBySelf(iot_uint8_t can_index);
extern iot_bool_t iot_CAN_HasWakeUpEvent(iot_uint8_t can_index);
extern void iot_CAN_ClearWakeUpEvent(iot_uint8_t can_index);

#endif
